#include "checksum_8.h"

uint8_t MakeChecksum8(uint8_t *inData, size_t length)
{
    uint32_t sum = 0;

    while (length-- > 0) {
        sum += *inData++;
        /* 折叠累加，保证保持 8bit 精度 */
        sum = (sum & 0xFFU) + (sum >> 8);
    }

    sum = (sum & 0xFFU);
    sum = (~sum) & 0xFFU;
    sum = (sum + 1U) & 0xFFU;

    return (uint8_t)sum;
}

